package org.yyf.resource.demo.quartz;

import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class MyTask {

	private final static Logger log = LoggerFactory.getLogger(MyTask.class);
	
	/**
	 * 时间间隔
	 */
	private final static int TIME_GRA =  6;
	
	private final static String JOB_ID = "myJob";
	
	private final static String TRIGGER_ID = "myTrigger";

	

	public static void main(String[] args) {
		// 创建一个jobDetail的实例，将该实例与Job.Class绑定
		JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity(JOB_ID).build();
		// 创建一个Trigger触发器的实例，定义该job立即执行，按时间粒度执行
		SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity(TRIGGER_ID).startNow()
				.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(TIME_GRA).repeatForever())
				.build();
		//cron触发器
		CronTrigger crontrigger = TriggerBuilder.newTrigger()
                .withIdentity(TRIGGER_ID).startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ? *"))
                
                .build();
		
		//取消检查更新
		System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");
		
		// 创建schedule实例
		StdSchedulerFactory factory = new StdSchedulerFactory();
		Scheduler scheduler;
		try {
			scheduler = factory.getScheduler();
			scheduler.start();
			scheduler.scheduleJob(jobDetail, trigger);
		} catch (SchedulerException e) {
			log.error(e.getMessage(),e);
			e.printStackTrace();
		}


	}

}
